package com.auto.survey.activity.monitoring.dao

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Update
import com.auto.survey.activity.monitoring.entity.MonitoringPointCtrlObservation

@Dao
interface MonitoringPointCtrlObservationDao {

    // 插入观测数据
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insertObservation(observation: MonitoringPointCtrlObservation): Long

    // 批量插入观测数据
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insertObservations(observations: List<MonitoringPointCtrlObservation>): List<Long>

    // 更新观测数据
    @Update
    suspend fun updateObservation(observation: MonitoringPointCtrlObservation): Int

    // 删除观测数据
    @Delete
    suspend fun deleteObservation(observation: MonitoringPointCtrlObservation): Int

    // 根据ID查询观测数据
    @Query("SELECT * FROM MonitoringPointCtrlObservation WHERE id = :id")
    suspend fun getObservationById(id: Int): MonitoringPointCtrlObservation?

    // 根据测点ID查询所有观测数据（按时间降序排列）
    @Query("SELECT * FROM MonitoringPointCtrlObservation WHERE monitoringPointId = :pointId ORDER BY observationTime DESC")
    suspend fun getObservationsByPointId(pointId: Int): List<MonitoringPointCtrlObservation>
}